_import("aiviki.util.vector");


	aiviki.event = function()
		{
    var listeners = new aiviki.util.vector(5);

		return {
		aa:1,
		getEL:function(o)
			{
			return document.getElementById(o);
			},
		getELS:function(o)
			{
			var nArray =[];
			var tags=document.all? document.all : document.getElementsByTagName("*");
			for(i=0; i<tags.length; i++){
				if(tags[i].className==o)
					{
					nArray.push(tags[i]);
					}
				}
			if(nArray.length==0)return null;
			return nArray;
			},
		addEventByObj:function(cmd,obj,eType,fn,oObj)
			{
			if(!fn || !fn.call)
				return false;

			if(!obj)return false;
			if(typeof oObj == 'undefined')
				{
				var cb = function(e)
					{
					return fn.call(obj,aiviki.event.getEvent(e),cmd);
					};
				}else{
				var cb = function(e)
					{
					return fn.call(oObj,aiviki.event.getEvent(e),cmd);
					};
				}

			var eventObj = [cmd,obj, eType, fn,cb,oObj];
			listeners.add(eventObj);

			if(obj.addEventListener)
				{
        obj.addEventListener(eType, cb, false);
        }else if(obj.attachEvent)
				{
        obj.attachEvent("on" + eType, cb);
        }

			return true;
			},
		addEventById:function(cmd,id,eType,fn,oObj)
			{
			if(!fn || !fn.call)
				return false;
			var obj = this.getEL(id);
			if(!obj)return false;
			return this.addEventByObj(cmd,obj,eType,fn,oObj);
			},
		addEventByClass:function(cmd,id,eType,fn,oObj)
			{
			if(!fn || !fn.call)
				return false;
			var objs = this.getELS(id);
			if(objs==null)return false;

			for(var i=0;i<objs.length;i++)
				{
				this.addEventByObj(cmd,objs[i],eType,fn,oObj);
				}
			return true;
			},
		getEvent: function(e)
			{
			var ev = e || window.event;
			if(!ev) 
				{
				var c = this.getEvent.caller;
				while(c)
					{
					ev = c.arguments[0];
					if(ev && Event == ev.constructor)
						{
						break;
						}
					c = c.caller;
					}
				}
			return ev;
			},
		removeEventById:function(id)
			{
			var o= null;
			for(var i=0;i<listeners.getSize();i++)
				{
				o = listeners.get(i);

				if(o[0]==id)
					{
					this.removeEventIndex(i);
					i--;
					}
				}
			},
		removeEventIndex:function(index)
			{
			
			var eventObj = listeners.get(index);
			if(eventObj !=null)
				{
				if(eventObj[1] ==null)return;
					if(eventObj[1].removeEventListener)
						{
						eventObj[1].removeEventListener(eventObj[2], eventObj[4], false);
						}else if(eventObj[1].detachEvent)
						{
						eventObj[1].detachEvent("on" + eventObj[2], eventObj[4]);
						}
	      delete eventObj[3];
	      delete eventObj[2];
	      delete eventObj[1];
	      delete eventObj[0];
	      delete eventObj;			
				listeners.removeByIndex(index);
				}
			}
		};
		}();

